package net.fdukedom.o3i.icq;

/**
 *
 * This class describes single SNAC item.
 * 
 * @author duke
 */
public class Snac {

    /**
     * Size of SNAC headers in bytes.
     */
    public static final int HEADERS_SIZE = 10;

    /**
     * Command family Id.
     */
    private short familyId;
    
    /**
     * Command type.
     */
    private short subType;
    
    /**
     * Command flags.
     */
    private byte[] flags = new byte[2];
    
    /**
     * Request id.
     */
    private int requestId;
    
    /**
     * Additional data.
     */
    private byte[] data;

    /**
     * Creates item from all required fields except flags.
     * 
     * @param familyId command family
     * @param subType command type
     * @param requestId request id
     * @param data data
     */
    public Snac(short familyId, short subType, int requestId, byte[] data) {
        this.familyId = familyId;
        this.subType = subType;
        this.requestId = requestId;
        this.data = data;
    }
    
    /**
     * Creates item from all required fields.
     * 
     * @param familyId command family
     * @param subType command type
     * @param requestId request id
     * @param flags flags
     * @param data data
     */
    public Snac(short familyId, short subType, int requestId, byte[] flags, byte[] data) {
        this.familyId = familyId;
        this.subType = subType;
        this.requestId = requestId;
        this.data = data;
        this.flags[0] = flags[0];
        this.flags[1] = flags[1];
    }

    public byte[] getData() {
        return data;
    }

    public short getFamilyId() {
        return familyId;
    }

    public byte[] getFlags() {
        return flags;
    }

    public int getRequestId() {
        return requestId;
    }

    public short getSubType() {
        return subType;
    }

    @Override
    public boolean equals(Object obj) {
        if (obj == null) {
            return false;
        }
        if (getClass() != obj.getClass()) {
            return false;
        }
        final Snac other = (Snac) obj;
        if (this.familyId != other.familyId) {
            return false;
        }
        if (this.subType != other.subType) {
            return false;
        }
        if (this.flags != other.flags && (this.flags == null || !this.flags.equals(other.flags))) {
            return false;
        }
        if (this.requestId != other.requestId) {
            return false;
        }
        if (this.data != other.data && (this.data == null || !this.data.equals(other.data))) {
            return false;
        }
        return true;
    }

    @Override
    public int hashCode() {
        int hash = 7;
        hash = 97 * hash + this.familyId;
        hash = 97 * hash + this.subType;
        hash = 97 * hash + (this.flags != null ? this.flags.hashCode() : 0);
        hash = 97 * hash + this.requestId;
        return hash;
    }
    
    
}
